/**
 *  @file HttpServer.h
 */
#ifndef _HTTPSERVER_H_
#define _HTTPSERVER_H_

#include "HttpEndPoint.h"
#include "../../collections/ArrayT.h"

namespace cppflib
{

namespace net
{

class Socket;
class ICancelContext;

namespace http
{

class HttpServerEndPoint;

/**
 *  A server side HTTP end point
 */
class _DLLAPI HttpServer : public BaseObject
{
private:
    HttpParams * pParams;
    collections::ListCppObjT<Socket> * pSockList;  // server may listen to more than one port
    collections::ArrayCppObjT<Socket> * pSockArray; // array of sockets which are waiting for incoming request
    ICancelContext *pServerCancelContext; // to help stop server immediately

private:
    HttpServer(void);
    void ReleaseBeforeThrowing();

public:
    HttpServer(HttpParams * pParams);
    virtual ~HttpServer(void);

    void StartServer();
    int GetListeningSocketCount();
    int GetIncomingClients(collections::ArrayCppObjT<HttpServerEndPoint> &endPointArray);
    ICancelContext * GetCancelContext();
};

} // end of namespace http

} // end of namespace net

} // end of namespace cppflib


#endif
